﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.BOM;
using FriendStar.Domain.IRepository.BOM;
using FriendStar.Repository.BOM;

namespace FriendStar.Application.BOM
{
    /// <summary>
	/// 数据视图 V_LXK_14_LX_ProductListIn_DA 对应的数据应用功能类。
	/// </summary>
	public class V_LXK_14_LX_ProductListIn_DAApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");  

        private IV_LXK_14_LX_ProductListIn_DARepository service = new V_LXK_14_LX_ProductListIn_DARepository();

        public List<V_LXK_14_LX_ProductListIn_DAEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<V_LXK_14_LX_ProductListIn_DAEntity>();
            expression = expression.And(t => t.UseUnit == UseUnit);
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.FProductionNO.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }

        public List<V_LXK_14_LX_ProductListIn_DAEntity> GetList(Pagination pagination, string GGDH, string FProduction, string ProductType, string AssembleLine)
        {
            var expression = ExtLinq.True<V_LXK_14_LX_ProductListIn_DAEntity>();
            expression = expression.And(t => t.UseUnit == UseUnit);
            if (!string.IsNullOrEmpty(GGDH))
            {
                expression = expression.And(t => t.GGDH.Contains(GGDH));
            }
            if (!string.IsNullOrEmpty(ProductType))
            {
                expression = expression.And(t => t.ProductType == ProductType);
            }
            if (!string.IsNullOrEmpty(AssembleLine))
            {
                expression = expression.And(t => t.AssembleLine == AssembleLine);
            }

            string extWhere = string.Empty;
            if (!string.IsNullOrEmpty(FProduction))
            {
                if (!string.IsNullOrEmpty(extWhere))
                {
                    extWhere += " AND ";
                }
                extWhere += string.Format("(FProductionNO LIKE '%{0}%' or FProductionName LIKE '%{0}%')", FProduction);
            }

            return service.FindList(expression, pagination, extWhere);
        }

        public V_LXK_14_LX_ProductListIn_DAEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
    }
}